"use strict"

// https://github.com/dcodeIO/ProtoBuf.js/wiki/Builder
var ProtoBuf = require('protobufjs');

var builder = ProtoBuf.loadProtoFile("./complex.proto"),
	Game = builder.build("Game"),
	Car = Game.Cars.Car;

var car = new Car({
	"model": "Rusty",
	"vendor": {
		"name": "Iron Inc.",
		"address": {
			"country": "US"
		}
	},
	"speed": "SUPERFAST" // also equivalent to "speed": 2
});

// OR: It's also possible to mix all of this!

// Afterwards, just encode your message:
var buffer = car.encode();
console.log(buffer.toString('hex'));